//
//  ZH_MineViewModel.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/11/13.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_MineViewModel.h"
//提现记录列表
#define withdrawals_record  @"/api/personal/withdrawals_record"
//用户资金记录列表
#define money_detail        @"/api/personal/money_detail"
//我的关注
#define follow              @"/api/personal/follow"
//用户获取个人信息
#define get_information     @"/api/personal/get_information"
//获取设置页面信息
#define show_option         @"/api/personal/show_option"
//我的课程 预约 ，线下，直播，点播
#define my_course           @"/api/student/my_course"
//我的课程订单
#define my_course_order     @"/api/student/my_course_order"
@implementation ZH_MineViewModel
//提现记录列表
- (void)withdrawalsResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:withdrawals_record dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
             resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.withdrawalsRecordArray removeAllObjects];
            [self.withdrawalsRecordArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//用户资金记录列表
- (void)moneyDetailResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:money_detail dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.moneyDetailArray removeAllObjects];
            [self.moneyDetailArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}

//我的关注
- (void)followResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:follow dictionaryParam:self.followParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.followArray removeAllObjects];
            [self.followArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }
    }];
}
//用户获取个人信息
- (void)getInformationResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:get_information dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}

//获取设置页面信息
- (void)showOptionResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:show_option dictionaryParam:@{@"token":[DATAMODEL.configDBHelper getToken]} withResultBlock:^(NSString *code, NSString *message, id data) {
        if (resultBlock) {
            resultBlock(code,message,data);
        }
    }];
}
//我的课程 预约 ，线下，直播，点播
- (void)myCourseResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:my_course dictionaryParam:self.myCourseParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"][@"data"];
        }
        if(resultArray.count > 0){
            [self.appointmentArray removeAllObjects];
            [self.liveArray removeAllObjects];
            [self.demandArray removeAllObjects];
            [self.offlineArray removeAllObjects];
            for (NSDictionary *dic in resultArray) {
                NSString *string = dic[@"way_name"];
                if ([string isEqualToString:@"线下"]) {
                    [self.offlineArray addObject:dic];
                }
                else if ([string isEqualToString:@"预约"]){
                    [self.appointmentArray addObject:dic];
                }
                else if ([string isEqualToString:@"直播"]){
                    [self.liveArray addObject:dic];
                }
                else if ([string isEqualToString:@"点播"]){
                    [self.demandArray addObject:dic];
                }
            }
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}

//我的订单 课程
- (void)myCourseListResultBlock:(WBRequestResultBlock)resultBlock{
    [[WB_MessageManager shareMessageManager] requestPostWithAction:my_course_order dictionaryParam:self.myCourseListParam withResultBlock:^(NSString *code, NSString *message, id data) {
        NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0];
        if (![data[@"data"] isKindOfClass:[NSNull class]]) {
            resultArray = data[@"data"][@"content"];
        }
        if(resultArray.count > 0){
            [self.myCourseListArray removeAllObjects];
            [self.myCourseListArray addObjectsFromArray:resultArray];
            if(resultBlock){
                resultBlock(code,message,data);
            }
        }
        else{
            if(resultBlock){
                resultBlock(code, message, nil);
            }
        }

    }];
}
#pragma mark - getter,setter
//提现记录列表
- (NSMutableArray *)withdrawalsRecordArray{
    if (!_withdrawalsRecordArray) {
        _withdrawalsRecordArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _withdrawalsRecordArray;
}
//用户资金记录列表
- (NSMutableArray *)moneyDetailArray{
    if (!_moneyDetailArray) {
        _moneyDetailArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _moneyDetailArray;
}
//我的关注
- (NSMutableDictionary *)followParam{
    if (!_followParam) {
        _followParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_followParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_followParam setObject:@"" forKey:@"type"];
        [_followParam setObject:@"" forKey:@"name"];
    }
    return _followParam;
}
- (NSMutableArray *)followArray{
    if (!_followArray) {
        _followArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _followArray;
}
//我的课程 预约 ，线下，直播，点播
- (NSMutableDictionary *)myCourseParam{
    if (!_myCourseParam) {
        _myCourseParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_myCourseParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_myCourseParam setObject:@"" forKey:@"type"];
    }
    return _myCourseParam;
}
//- (NSMutableArray *)myCourseArray{
//    if (!_myCourseArray) {
//        _myCourseArray = [[NSMutableArray alloc] initWithCapacity:0];
//    }
//    return _myCourseArray;
//}
- (NSMutableArray *)appointmentArray{
    if (!_appointmentArray) {
        _appointmentArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _appointmentArray;
}
- (NSMutableArray *)offlineArray{
    if (!_offlineArray) {
        _offlineArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _offlineArray;
}
- (NSMutableArray *)liveArray{
    if (!_liveArray) {
        _liveArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _liveArray;
}
- (NSMutableArray *)demandArray{
    if (!_demandArray) {
        _demandArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _demandArray;
}

//我的订单 课程
- (NSMutableDictionary *)myCourseListParam{
    if (!_myCourseListParam) {
        _myCourseListParam = [[NSMutableDictionary alloc] initWithCapacity:0];
        [_myCourseListParam setObject:[DATAMODEL.configDBHelper getToken] forKey:@"token"];
        [_myCourseListParam setObject:@"" forKey:@"status"];
    }
    return _myCourseListParam;
}
- (NSMutableArray *)myCourseListArray{
    if (!_myCourseListArray) {
        _myCourseListArray = [[NSMutableArray alloc] initWithCapacity:0];
    }
    return _myCourseListArray;
}
@end
